﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace HZY.Admin.Controllers
{
    using HZY.Toolkit;
    using HZY.Admin.Core;
    using HZY.DTO.Sys;
    using HZY.Logic.Sys;

    /// <summary>
    /// 授权
    /// </summary>
    [ApiExplorerSettings(GroupName = nameof(ApiVersionsEnum.Admin))]
    public class AuthorizationController : BaseController
    {
        protected AccountLogic logic { get; }

        public AuthorizationController(AccountLogic _logic)
        {
            this.logic = _logic;
        }

        /// <summary>
        /// 检查帐户并获取 token
        /// </summary>
        /// <param name="authUserDto">Dto</param>
        /// <returns></returns>
        [HttpPost(nameof(Check))]
        public async Task<ApiResult> Check([FromBody]AuthUserDto authUserDto)
        {
            var _Toekn = await this.logic.CheckedAsync(authUserDto.UserName, authUserDto.UserPassword, authUserDto.LoginCode);

            var _TokenType = "Bearer ";

            return this.JsonOk(new
            {
                token = _TokenType + _Toekn,
                tokenType = _TokenType
            });
        }


    }
}